//
//  adDetailView.m
//  试验
//
//  Created by Tiancheng on 16/10/31.
//  Copyright © 2016年 Tiancheng. All rights reserved.
//

#import "adDetailView.h"
#import "UILabel+LabelHeightAndWidth.h"
#import "Macros.h"
#import "UIImageView+WebCache.h"

@implementation adDetailView
@synthesize picMutableArray,image_y;

-(id)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self)
    {
        [self setUI];
    }
    return  self;
}
-(void)setUI
{
    //添加标题
    self.goodsDetailTitle=[[UILabel alloc]initWithFrame:CGRectMake(0, 8, screenWidth, 21)];
    self.goodsDetailTitle.textColor=[UIColor blackColor];
    self.goodsDetailTitle.font=[UIFont systemFontOfSize:17.0f];
    self.goodsDetailTitle.textAlignment=NSTextAlignmentCenter;
    [self addSubview:self.goodsDetailTitle];
    //添加文字内容
    self.goodsDetailContent=[[UILabel alloc]initWithFrame:CGRectMake(10, 8+21+8, screenWidth-20, 10)];
    self.goodsDetailContent.textColor=[UIColor grayColor];
    self.goodsDetailContent.font=[UIFont systemFontOfSize:15.0f];

    //边框
    self.goodsDetailContent.layer.borderColor = [[UIColor redColor]CGColor];
    self.goodsDetailContent.layer.borderWidth = 0.5f;
    self.goodsDetailContent.layer.masksToBounds = YES;
    [self addSubview:self.goodsDetailContent];
    self.goodsDetailContent.numberOfLines=0;
//    self.goodsDetailTitle.backgroundColor=[UIColor orangeColor];
    self.backgroundColor=[UIColor whiteColor];
}
// 在该`setter`方法中取出模型属性，给对应的子控件赋值
-(void)setAdModel:(adDetailModel *)adModel
{
    picMutableArray=[NSMutableArray array];
    picMutableArray =adModel.picMutableArray;
    self.goodsDetailTitle.text=adModel.titleString;
    self.goodsDetailContent.text=adModel.contentString;
    float height=[UILabel getHeightByWidth:self.goodsDetailContent.frame.size.width title:self.goodsDetailContent.text font:[UIFont systemFontOfSize:15.0f]];
    self.goodsDetailContent.frame=CGRectMake(self.goodsDetailContent.frame.origin.x, self.goodsDetailContent.frame.origin.y, self.goodsDetailContent.frame.size.width,height);
    image_y=self.goodsDetailContent.frame.origin.y+self.goodsDetailContent.frame.size.height+8;

}
-(void)addpic:(NSMutableArray*)picarray
{
    for (int i=0; i<picMutableArray.count; i++)
    {
        self.goodsPicture=[[UIImageView alloc]initWithFrame:CGRectMake(0, image_y+140*i, screenWidth, 140)];
        NSURL *imagePath=picMutableArray[i];
        [self.goodsPicture sd_setImageWithURL:imagePath placeholderImage:[UIImage imageNamed:@"banner"]];
        self.goodsPicture.backgroundColor=[UIColor orangeColor];
        [self addSubview:self.goodsPicture];
    }
    self.frame=CGRectMake(self.frame.origin.x,self.frame.origin.y , screenWidth, image_y+picarray.count*140);

}
@end
